<?php
namespace uploadPic;

class UploadPic{
	private $message;
	//uploads pictures to server /../uploads
	public function uploadCurrentPic(){
		
		//if they DID upload a file...
		if($_FILES['photo']['name'])
		{
			//if no errors...
			if(!$_FILES['photo']['error'])
			{
				$new_file_name = strtolower($_FILES['photo']['tmp_name']);
				$valid_file = TRUE;
				if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB
				{
					$valid_file = false;
					$this->message = 11;
				}
				if(($_FILES["photo"]["type"] == "image/gif") //must be one of this files
						|| ($_FILES["photo"]["type"] == "image/jpeg")
						|| ($_FILES["photo"]["type"] == "image/jpg")
						|| ($_FILES["photo"]["type"] == "image/pjpeg")
						|| ($_FILES["photo"]["type"] == "image/x-png")
						|| ($_FILES["photo"]["type"] == "image/png")){
				}else{
					$valid_file = false;
					$this->message = 12;
				}

				if($valid_file)
				{
					$currentdir = getcwd();
					$target = $currentdir . "/model/uploads/" . basename($_FILES['photo']['name']);
					move_uploaded_file($_FILES['photo']['tmp_name'], $target);
					$this->message = 13;	
				}
			}
			else
			{
				throw new Exception ('Ooops!  Your upload triggered the following error:  '.$_FILES['photo']['error']);
			}
		}
	}
	public function getMessage(){
		if(isset($this->message)){
			return $this->message;
		}
	}
	public function deleteImg($imgName){
		echo $imgName;
		unlink($imgName);
	}	
}











